import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        /**
         * 是否需要强制登录
         */
        forcedLogin: true,
        hasLogin: false,
        userName: "",
		avatarUrl: "",
		openid: "",
		sessionKey: ""
    },
    mutations: {
        login(state, user) {
            state.userName = user.nickName || '新用户';
			state.avatarUrl = user.avatarUrl;
			state.hasLogin = true;
			state.openid = user.openid;
			state.sessionKey = user.sessionKey;
        },
        logout(state) {
            state.userName = "";
			state.avatarUrl = "";
			state.openid = "";
			state.sessionKey = "";
            state.hasLogin = false;
			uni.clearStorage();
        }
    }
})

export default store
